package com.yingxue.demo.controller;

import com.yingxue.demo.exception.BizException;
import com.yingxue.demo.exception.enums.UnauthorizedExceptionEnum;
import com.yingxue.demo.util.ResultVOUtil;
import com.yingxue.demo.vo.req.TestRequestVO;
import com.yingxue.demo.vo.resp.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @Package: com.company.scaffold.controller
 * @Author: Mr.Waves
 * @Date: 2020-03-08 16:31
 * @Description:
 **/
@Api(tags = "测试模块")
@RestController
@RequestMapping("test")
public class TestController {

    @ApiOperation(value = "测试按照统一格式（ResultVO）返回数据")
    @GetMapping("resultVO")
    public ResultVO responseVOTest() {
        return ResultVOUtil.success("abc");
    }

    @ApiOperation(value = "测试全局处理主动抛出的业务异常")
    @GetMapping("businessException")
    public ResultVO businessExceptionTest() {
        throw new BizException(UnauthorizedExceptionEnum.TOKEN_EXPIRED);
    }

    @ApiOperation(value = "测试全局处理非业务异常")
    @GetMapping("exception")
    public ResultVO exceptionTest() {
        int i = 1/0;
        return ResultVOUtil.success(null);
    }

    @ApiOperation(value = "测试Validation")
    @PostMapping("validation")
    public ResultVO validationTest(@RequestBody @Valid TestRequestVO requestVO) {
        return ResultVOUtil.success(null);
    }
}
